home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hunter 2006
/
Hunter 2006.iso
/
soft
/
sleipnir241.exe
/
{app}
/
scripts
/
ŒŸõ
/
Grep.js
next >
Wrap
Text File
|
2006-06-15
|
7KB
|
281 lines
var obj, document, id, window;
obj = new ActiveXObject("Sleipnir.API");
id = obj.GetDocumentID(obj.ActiveIndex);
document = obj.GetDocumentObject(id);
var CurSel;
if (document == null) {
obj.MessageBox('Document é¬èJé⌐éΩé─éóé▄é╣é±');
}else{
var query = '('+obj.SearchBarString.replace(/( |ü@)/g,'|')+')';
var GD = new TGrepData(obj);
obj.OutputVisible = true;
obj.OutputClear();
obj.OutputAddString('Åêù¥Æåé┼é╖...');
obj.OutputAddString('');
var progress;
for (var i= 0; i < obj.GetCount; i++){
id = obj.GetDocumentID(i);
GD.AddBookmark(id, query);
progress = '0% üáüáüáüáüáüáüáüáüáüá 100%';
for (var j = 0; j < (i + 1) / obj.GetCount * 10; j++){
progress = progress.replace('üá', 'üí');
}
obj.OutputDeleteString(1);
obj.OutputAddString(progress);
}
GD.OPText.push('âXâNâèâvâgé╠ÅIù╣');
GD.Output();
while (true){
WScript.Sleep(100);
CurSel = obj.OutputCurSel;
//âXâNâèâvâgé╠ÅIù╣é≡æIæ≡é╡é─éóé╜éτâïü[âvé⌐éτö▓é»éΘ
if (CurSel == obj.OutputGetCount() -1){
obj.OutputClear();
obj.OutputVisible = false;
break;
}
//Æ╝æOé╔æIæ≡é╡é─éóé╜ìsé╞î╗ì▌æIæ≡é╡é─éóéΘìsé¬ê┘é╚é┴é─éóé╜éτâWâââôâv
if (GD.CurSelected != CurSel){
GD.CurSelected = CurSel;
//IDé╠îƒì⌡
while (true){
if (obj.OutputGetString(CurSel).match(/^\d+/) > 0){
id = obj.OutputGetString(CurSel).match(/^\d+/);
break;
}
CurSel--;
}
FindTab(id);
if (GD.Bookmark[GD.CurSelected] != ''){
var text = GD.DocumentObject[CurSel].body.createTextRange();
text.moveToBookmark(GD.Bookmark[GD.CurSelected]);
text.select();
text = null;
}
}
}
GD = null;
document = null;
}
obj = null;
//[MAINEND]
/*
TGrepData
Bookmarké╠ĵô╛ôÖé═é╖é╫é─é▒é╠âIâuâWâFâNâgé≡Æ╩é╡é─ìséñ
*/
function TGrepData(obj){
this.obj = obj;
//public method
this.AddBookmark = AddBookmark;
this.Output = Output;
//private method
this.SetMatchText = SetMatchText;
this.SetBookmark = SetBookmark;
this.s = s;
this.Bookmark = new Array();
this.DocumentObject = new Array();
this.OPText = new Array();
this.CurSelected = 0;
this.MatchText;
}
/*
AddBookmark(id, query)
id : documentID
query : É│ïKò\î╗
IDé⌐éτDocumentâIâuâWâFâNâgé≡ĵô╛üAÄqâüâ\âbâhé≡ùpéóé─TGrepDataé╠MatchTextüABookmarküAOPTexté≡É▌ÆΦüB
*/
function AddBookmark(id, query){
document = this.obj.GetDocumentObject(id);
if (document == null){
return(false);
}else{
var aod = new ArrayOfDocument();
aod.GetDocument(id, null);
}
for (var i = 0; i < aod.list.length; i++){
this.SetMatchText(aod.list[i], query);
this.SetBookmark(id, aod.list[i], this.MatchText);
}
aod = null;
return(true);
}
/*
Output()
Outputé╔OPTexté≡Åoù═
*/
function Output(){
this.obj.OutputClear();
for (var i = 0; i < GD.OPText.length; i++){
this.obj.OutputAddString(this.OPText[i]);
}
this.obj.OutputVisible = true;
this.obj.OutputCurSel = 0;
}
/**
* SetMatchText(document, query)
* É│ïKò\î╗queryé┼documenté≡îƒì⌡é╡â}âbâ`é╖éΘò╢ÄÜù±é≡ò╘é╖
* ê°Éö : document documentâIâuâWâFâNâg
* query îƒì⌡é╖éΘò╢ÄÜù±üBÉ│ïKò\î╗
* û▀éΦÆl : â}âbâ`é╖éΘò╢ÄÜù±é≡èiö[é╖éΘözù±üBé╜é╛é╡0ö╘û┌é╠özù±é═ï≤ò╢ÄÜù±
*
**/
function SetMatchText(document, query){
var text = document.body.innerText;
var re = new RegExp(query, 'ig');
var matchtext = text.match(re);
var result = new Array();
var original;
if (matchtext != null){
result.push('');
for (var i = 0; i < matchtext.length; i++){
original = true;
//é╖é┼é╔ô»é╢âLü[âÅü[âhé¬ôoÿ^é│éΩé─éóé╜éτæ╜Ådôoÿ^é╡é╚éó
for (var j = 0; j < result.length; j++){
if (matchtext[i].toLowerCase() == result[j].toLowerCase()){
original = false;
break;
}
}
if (original){
result.push(matchtext[i]);
}
}
}
re = null;
this.MatchText = result;
result = null;
}
/**
* SetBookmark(document, query)
* MatchTexté⌐éτê╩Æué≡î│é╔â\ü[âgé╡é╜TextRangeâIâuâWâFâNâgé╠Bookmark,ïyé╤OPTexté≡É▌ÆΦüB
* ê°Éö : document documentâIâuâWâFâNâg
query TGrepData.MatchText
*
**/
function SetBookmark(id, document, query){
var TempBookmark = new Array();
var SortData = new Array();
var TempOPText = new Array();
var text = document.body.createTextRange();
var temp = 0;
for (var i = 1; i < query.length ; i++){
while (text.findText(query[i])){
TempBookmark.push(text.getBookmark());
var dup = text.duplicate();
dup.moveStart('character', -20);
dup.moveEnd('character', 20);
TempOPText.push(' '+dup.text);
dup = null;
SortData.push(text.offsetTop+':'+temp+':'+text.offsetLeft);
text.move('character', 1);
temp++;
}
text.move('textedit', -1);
}
if (TempBookmark.length != 0){
this.Bookmark.push('')
this.OPText.push(id+': ['+document.title+']');
}
SortData.sort(this.s);
//â\ü[âgîïë╩é╔Å]éóBookmarkôÖé≡èiö[é╡é─éóé¡
for (var j = 0; j < SortData.length ; j++){
SortData[j].match(/^-?\d+:(.*):-?\d+$/);
this.Bookmark.push(TempBookmark[RegExp.$1]);
this.OPText.push(TempOPText[RegExp.$1]);
if (j == 0){
this.DocumentObject[this.OPText.length -2] = document;
}
}
if (TempBookmark.length > 0){
this.Bookmark.push('')
this.OPText.push('');
}
text = null;
TempBookmark = null;
SortData = null;
TempOPText = null;
}
/**
* s(a, b)
* SortDataé≡â\ü[âgé╖éΘ
*
**/
function s(a, b){
if ((a.match(/^-?\d+/) - b.match(/^-?\d+/)) == 0){
//Åπé⌐éτé╠ê╩Æué¬êΩÆvé╡é╜éτüAì╢é⌐éτé╠ê╩Æué┼â\ü[âg
return(a.match(/-?\d+$/) - b.match(/-?\d+$/));
}
return(a.match(/^-?\d+/) - b.match(/^-?\d+/));
}
/*
* FindTab(id)
* idé⌐éτû┌ôIé╠â^âué≡î⌐é┬é»Åoé╡âAâNâeâBâué╔é╖éΘ
* ê°Éö : id DocumentID
*
**/
function FindTab(id){
var obj;
obj = new ActiveXObject("Sleipnir.API");
for (i = 0; i < obj.GetCount; i++){
if (obj.GetDocumentID(i) == id){
obj.ActiveIndex = i;
}
}
obj = null;
}
/**
*ArrayOfDocument
*âtâîü[âÇâyü[âWé╠é╖é╫é─é╠âhâLâàâüâôâgé≡ò█Ä¥é╖éΘâNâëâX
*âüâ\âbâh : GetDocument documentâIâuâWâFâNâgé≡ĵô╛é╖éΘ
*âvâìâpâeâB : list documentâIâuâWâFâNâgé╠özù±
*
**/
function ArrayOfDocument(){
var obj = new ActiveXObject("Sleipnir.API");
this.obj = obj;
this.GetDocument = GetDocument;
this.list = new Array();
}
/**
*[ArrayOfDocument]
*GetDocument(id, document)
*documentâIâuâWâFâNâgé≡ĵô╛é╡üAlisté╔âZâbâg
*ê°Éö : id DocumentID
document documentâIâuâWâFâNâg
*
**/
function GetDocument(id, document){
if (document == null){
document = this.obj.GetDocumentObject(id);
this.GetDocument(id, document);
}else if (document.frames.length > 0){
for (var k = 0; k < document.frames.length; k++) {
try{
var window = document.frames.item(k);
this.GetDocument(id, window.document);
}
catch(e){
break;
}
}
}else{
this.list.push(document);
}
}
//[END]